package com.zx.task.manager.controller;

import com.zx.core.wrapper.ListWrapper;
import com.zx.core.wrapper.PageWrapper;
import com.zx.task.manager.param.TaskOperationsParam;
import com.zx.task.manager.service.ITaskOperationsService;
import com.zx.task.manager.vo.TaskOperationsVO;
import com.zx.validation.annotation.ParameterValidation;
import com.zx.validation.annotation.ParameterValidations;
import com.zx.validation.enums.ValidateRulesEnum;
import com.zx.validation.groups.Query;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * description: 任务操作记录控制器 <br>
 * create: 2025-10-13 20:15
 * </p>
 *
 * @author zhou  xun
 */
@RestController
@RequestMapping("/taskOperations")
@RequiredArgsConstructor
public class TaskOperationsController {

    private final ITaskOperationsService iTaskOperationsService;

    /**
     * 分页查询任务操作记录列表
     *
     * @param taskOperationsParam 查询参数
     * @return 任务操作记录分页列表
     */
    @PreAuthorize("hasAuthority('task:operation:list')")
    @GetMapping("/list")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "任务操作记录参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Query.class})
    )
    public PageWrapper<TaskOperationsVO> list(TaskOperationsParam taskOperationsParam) {
        return iTaskOperationsService.getTaskOperationsVOListByPage(taskOperationsParam);
    }

    /**
     * 根据任务ID查询任务操作记录列表
     *
     * @param taskId 任务ID
     * @return 任务操作记录列表
     */
    @PreAuthorize("hasAuthority('task:operation:list')")
    @GetMapping("/task/{taskId}")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "任务ID", rules = {ValidateRulesEnum.NOT_NULL})
    )
    public ListWrapper<TaskOperationsVO> listByTaskId(@PathVariable("taskId") String taskId) {
        return iTaskOperationsService.getTaskOperationsListByTaskId(taskId);
    }

}